package com.example.application2;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class MainActivity extends AppCompatActivity {

    private Button btn_call;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn_call = findViewById(R.id.call);
        btn_call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(MainActivity.this, "缺少打电话权限", Toast.LENGTH_LONG).show();
                    return;
                }
                String phoneNumber = "18612951217";
                String encodedPhoneNumber = null;
                try {
                    encodedPhoneNumber = URLEncoder.encode(phoneNumber, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + encodedPhoneNumber)));
            }
        });
        Button btn_toSp = findViewById(R.id.toSP);
        btn_toSp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, ShrdpreActivity.class);
                startActivity(intent);
                finish();
            }
        });
        Button btn_toF = findViewById(R.id.toF);
        btn_toF.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, FilewrActivity.class);
                startActivity(intent);
                finish();
            }
        });
        Button btn_toC = findViewById(R.id.toC);
        btn_toC.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, ConnecterActivity.class);
                startActivity(intent);
                finish();
            }
        });
        Button btn_toSS = findViewById(R.id.toSS);
        btn_toSS.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, StartServiceActivity.class);
                startActivity(intent);
                finish();
            }
        });
        Button btn_toT = findViewById(R.id.toT);
        btn_toT.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, TheardDemoActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }
}
